﻿(function (jQuery, window) {
    var CNOOCLoading = {
        $loadingShadow: null,
        $loadingContainer: null,
        isInit: false,
        init: function () {
            if (!this.isInit) {
                this.$loadingShadow = $('<div id="ajax-loading" style="display: none; position: absolute; background: #aaaaaa; opacity: 0.3;top:0;left:0;filter: Alpha(Opacity=30)"></div>');
                $(document.body).append(this.$loadingShadow);

                this.$loadingContainer = $("<div id='loading-panel' style='display: none; position: absolute;top:0;left:0;'>").append("<img src='/images/loading.gif' />");
                var img = $("img", this.$loadingContainer).css({ position: "absolute", "top": $(window).height() / 2 + $(document).scrollTop(), left: $(window).width() / 2 - 50, "z-index": "200000000" });
                $(document.body).append(this.$loadingContainer);
                this.isInit = true;
            }
        },

        show: function () {

            var css = { width: $(window).width(), height: $(document).height(), "z-index": "10000" };
            this.$loadingShadow.css(css);
            css["z-index"] = "100001";
            css["display"] = "none";
            this.$loadingContainer.css(css);
            var img = $("img", this.$loadingContainer).css({ "top": $(window).height() / 2 + $(document).scrollTop() - 30 });
            this.$loadingContainer.show();
            this.$loadingShadow.show();
        },
        hide: function () {
            this.$loadingContainer.hide();
            this.$loadingShadow.hide();
        },
        state: function () {
            console.log(this.$loadingContainer.css("display"));
            console.log(this.$loadingShadow.css("display"));
        },
        isShow: function () {
            return this.$loadingContainer.css("display") == "block";
        }
    };

    //CNOOCLoading.init();

    jQuery.CNOOCLoading = CNOOCLoading;
})($, window);